<template>
  <div class="category">
    <!-- 搜索框 -->
    <van-search v-model="value" placeholder="请输入搜索关键词" shape="round" />
    <div class="bottom">
      <div class="left">
        <!-- 左边导航 -->
        <van-sidebar v-model="activeKey">
          <van-sidebar-item
            :title="item.name"
            v-for="item in categoryList"
            :key="item.id"
            @click="onChange(item.id)"
            href="#"
          />
        </van-sidebar>
      </div>
      <!-- 右边内容 -->
      <div class="right">
        <div class="right_top">
          <img :src="currentCategory.banner_url" alt="" />
          <h3>{{ currentCategory.front_name }}</h3>
        </div>
        <div class="right_center">
          <van-divider
            :hairline="true"
            content-position="center"
            :style="{
              color: '#000',
              borderColor: '#cccccc',
              padding: '0 80px',
            }"
          >
            {{ currentCategory.name }}
          </van-divider>
        </div>
        <van-grid :column-num="3">
          <van-grid-item
            v-for="item in currentCategory.subCategoryList"
            :key="item.id"
            :icon="item.banner_url"
            :text="item.name"
          />
        </van-grid>
      </div>
    </div>
  </div>
</template>
<script>
// 引入分类请求接口
import { getCategory, getCurrentCategory } from "@/utils/https";
export default {
  name: "Category",
  data() {
    return {
      value: "", //搜索框模糊搜索内容
      activeKey: 0, //当前选中的类型
      categoryList: [], //侧边栏所有的分类数据
      currentCategory: {}, //当前分类
    };
  },
  components: {},
  methods: {
    // onChange(id) {
    //   // this.activeKey = id;
    //   getCurrentCategory({ id:id}).then(res=>{
    //     this.currentCategory=res.data.data.currentCategory
    //   }).catch(e=>{
    //     // console.log(e);
    //   });
    // },
    // getdata() {
    //   getCategory().then((res) => {
    //     this.categoryList = res.data.data.categoryList;
    //     this.currentCategory = res.data.data.currentCategory;
    //   });
    // },

    onChange(id) {

      // 切换左边侧边导航
      // this.activeKey = index;
      console.log(this);
      console.log(id);
      getCurrentCategory({ id: id })
        .then((res) => {
          // console.log(res);
          this.currentCategory = res.data.data.currentCategory;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getData() {
      getCategory().then((res) => {
        // console.log(res);
        this.categoryList = res.data.data.categoryList;
        this.currentCategory = res.data.data.currentCategory;
      });
    },
  },

  created() {
    this.getData();
    // this.getCurrentCategory()
  },
  mounted() {},
};
</script>
<style lang="less" scoped>
.category {
  .bottom {
    height: 100%;
    display: flex;
    justify-content: space-between;
    .left {
      height: 100%;
      background-color: #f7f8fa;
      font-size: 14px;
      ul {
        width: 75px;
        li {
          height: 60px;
          line-height: 60px;
          padding-left: 10px;
          .p {
            border-left: 5px solid red;
          }
        }
        .li {
          background-color: white;
        }
      }
    }
    .right {
      flex: 1;
      .right_top {
        width: 97%;
        border-radius: 5px;
        overflow: hidden;
        margin: 0 2px;
        box-shadow: 0px 1px 5px #000;
        position: relative;
        img {
          filter: brightness(0.5);
          width: 100%;
          height: 150px;
        }
        h3 {
          position: absolute;
          top: 80px;
          left: 80px;
          font-size: 16px;
          color: white;
        }
      }
    }
  }
}
</style>
